<template>
  <div class="table">
    <el-table
      :data="tableData"
      :loading="loading"
      style="width: 100%"
      :header-cell-style="{
        background: '#F1F1F1',
        'font-size': '14px',
        'font-weight': 600,
        color: '#333333',
      }"
      :cell-style="{
        'font-size': '14px',
        'font-weight': 400,
        color: '#333333',
      }"
      @sort-change="sortChange"
    >
      <el-table-column label="序号" min-width="60" fixed="left">
        <template #default="scope">
          {{ (scope.$index + 1).toString().padStart(2, "0") }}
        </template>
      </el-table-column>
      <el-table-column prop="licensePlate" label="车牌号" min-width="100" fixed="left" />
      <el-table-column prop="phone" label="手机号码" min-width="120" />
      <el-table-column
        prop="arrearsCount"
        label="欠费订单数(笔)"
        sortable
        min-width="150"
      />
      <el-table-column
        prop="arrearsSum"
        label="欠费总金额(元)"
        sortable="custom"
        width="150"
        align="right"
      />
      <el-table-column label="操作" width="60" fixed="right">
        <template #default="scope">
          <el-button
            @click="details(scope.row)"
            type="primary"
            size="small"
            link
            style="color: #007aff"
            >详情</el-button
          >
        </template>
      </el-table-column>
      <template #empty>
        <el-empty :image="imgNone" />
      </template>
    </el-table>
  </div>
</template>

<script setup>
import { reactive, ref, defineProps } from "vue";
const imgNone = new URL("@/assets/image/imgNone.png", import.meta.url).href;
const emits = defineEmits(["table"]);

const props = defineProps({
  tableData: {
    type: Object,
    default: () => {},
  },
  loading: {
    type: Boolean,
    default: false,
  },
});

const details = (row) => {
  row.operation = 1;
  emits("table", row);
};

const sortChange = (column) => {
  let row = {};
  console.log("Column:", column);
  if (column.prop === "arrearsSum") {
    row.orderBy = "sum";
    row.operation = 2;
    if (column.order === "ascending") {
      // 上
      row.sort = 1;
    } else if (column.order === "descending") {
      // 下
      row.sort = 0;
    } else {
      row.orderBy = "";
      row.sort = "";
    }
  } else if (column.prop === "arrearsCount") {
    row.orderBy = "count";
    row.operation = 3;
    if (column.order === "ascending") {
      // 上
      row.sort = 1;
    } else if (column.order === "descending") {
      // 下
      row.sort = 0;
    } else {
      row.orderBy = "";
      row.sort = "";
    }
  }
  emits("table", row);
};
</script>

<style lang="less" scoped>
.table {
  margin-bottom: 15px;
}
</style>
